﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CsharpTrainer.Linq.Service.Northwind;
using CsharpTrainer.Linq;
using Zeus.Thunder.Core;

namespace SharpTrainer.Linq
{
    class AddCascadeTablesTest : ITestCase
    {
        public void Run()
        {
            /*
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i <= 51; i++)
                sb.Append("C");
            */

            Guid caId, cbId, ccId;
            
            caId = Guid.NewGuid();
            CascadeA tableA = new CascadeA
            {
                CaId = caId,
                CaContent = "Content A1"
            };
            
            List<CascadeB> tablesB = new List<CascadeB>();
            List<CascadeC> tablesC = new List<CascadeC>();
            CascadeB tableB;
            CascadeC tableC;
            for (int i = 1; i <= 3; i++)
            {
                cbId = Guid.NewGuid();
                tableB = new CascadeB
                {
                    CbId = cbId,
                    CaId = caId,
                    CbContent = "Content B" + i.ToString()
                };
                tablesB.Add(tableB);

                for (int j = 1; j <= 3; j++)
                {
                    ccId = Guid.NewGuid();
                    tableC = new CascadeC
                    {
                        CcId = ccId,
                        CbId = cbId,
                        CcContent = "Content C" + i.ToString() + j.ToString()
                        //CcContent = sb.ToString()
                    };
                    tablesC.Add(tableC);
                }
            }

            CascadeTableService service = new CascadeTableService();
            bool result = service.AddCascadeTables(tableA, tablesB, tablesC);
            if (result)
                Console.WriteLine("Add Cascade Tables Successfully!");
            else
                Console.WriteLine("Failed to add cascade tables!");
        }
    }
}
